import dao.UserDao;
import entity.Emp;
import entity.User;
import factory.MyFactory;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import services.UserServices;


public class TsetFactory {
    @Test
    public void test7(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("/application.xml");
        UserDao e = (UserDao) ac.getBean("ud");
        UserDao e1 = (UserDao) ac.getBean("ud");
        UserDao e2 = (UserDao) ac.getBean("ud");
        System.out.println(e==e1);
        System.out.println(e==e2);

    }
    @Test
    public void test6(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("/application.xml");
        UserServices e = (UserServices) ac.getBean("userServices2");
        e.sayHi();
    }
    @Test
    public void test5(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("/application.xml");
        Emp e = (Emp) ac.getBean("emp");
        System.out.println(e);
    }


    @Test
    public void test4(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("/application.xml");
        User u = (User) ac.getBean("user");
        System.out.println(u);
    }


    @Test
    public void test3(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("/application.xml");
        UserServices us = (UserServices) ac.getBean("userServices");
        us.sayHi();
    }



    @Test
    public void test2() {
        // 实例化工厂  实例化sprin 容器
        ApplicationContext ac = new ClassPathXmlApplicationContext("/application.xml");
        UserDao userDao = (UserDao) ac.getBean("userDao");
        userDao.userInfo();
        UserServices us = (UserServices) ac.getBean("userServices");
        us.sayHi();
    }

    @Test
    public void test() {
        MyFactory mf = new MyFactory();
        UserDao userDao = (UserDao) mf.getBean("userDao");
        userDao.userInfo();
    }
}
